package oaSystem.biz.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oaSystem.biz.ActivityScheduleBiz;
import oaSystem.entity.Activity;
import oaSystem.entity.ActivityActor;
import oaSystem.entity.ActivitySchedule;
import oaSystem.mapper.ActivityActorMapper;
import oaSystem.mapper.ActivityMapper;
@Service
public class ActivityScheduleBizImpl implements ActivityScheduleBiz {
	@Autowired
	private ActivityMapper activityMapper;
	@Autowired
	private ActivityActorMapper activityActorMapper;
	/**
	 * 查询未来的活动
	 * @return
	 */
	@Override
	public List<ActivitySchedule> findEventAfterToday(Integer employeeId) {
		List<ActivitySchedule> activitySchedules=new ArrayList<ActivitySchedule>();
		List<Activity> activityList = activityMapper.findActivityAfterToday(employeeId);
		List<ActivityActor> actorList = activityActorMapper.findActivityActorAfterToday(employeeId);
		
		if(actorList!=null&&actorList.size()>0){
			Integer activityId=null;
			for (ActivityActor activityActor : actorList) {
				Activity activity = activityActor.getActivity();
				if(activity.getId()!=activityId){
					activityId=activity.getId();
					activityList.add(activity);
				}
			}
		}
		
		String start="";
		ActivitySchedule activitySchedule=null;
		List<Activity> list = null;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		for (Activity activity : activityList) {
			if(start.equals(format.format(activity.getStartTime()))){
				list.add(activity);
				activitySchedule.setEvenList(list);
			}else{
				activitySchedule=new ActivitySchedule();
				activitySchedules.add(activitySchedule);

				start=format.format(activity.getStartTime());
				activitySchedule.setStartTime(activity.getStartTime());
				list = new ArrayList<Activity>();
				list.add(activity);
				activitySchedule.setEvenList(list);
			}
			
			
		}
		return activitySchedules;
	}

}
